package com.EpidemicPrevention.controller;

import com.EpidemicPrevention.pojo.Admin;
import com.EpidemicPrevention.service.AdminServicelmpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/AdminController")
public class AdminController {
    @Autowired
    private AdminServicelmpl adminService;


    @GetMapping("/login")
    @ResponseBody
    @CrossOrigin
    public JSON login(Admin admin, HttpSession session) {
        return adminService.login(admin, session);
    }


    /*
     *添加用户
     * @Prama user 实体类
     * @return
     */
    @GetMapping("/addAdmin")
    @ResponseBody
    @CrossOrigin
    public JSON addAdmin(Admin admin) {
        return adminService.addAdmin(admin);
    }

    /*
     *修改密码
     * @Prama User,pwd1,pwd2
     * @return
     */
    @GetMapping("/updateAdminPwd")
    @ResponseBody
    @CrossOrigin
    public JSON updateAdminPwd(Admin admin, String pwd1, String pwd2) {
        return adminService.updateAdminPwd(admin,pwd1,pwd2);
    }


    @GetMapping("/deleteAdmin")
    @ResponseBody
    @CrossOrigin
    public JSON deleteAdmin(int id) {
        return adminService.deleteAdmin( id);
    }

    //    存储用户信息
//    @Param user
//    @return
    @GetMapping("/saveAdminInfo")
    @ResponseBody
    @CrossOrigin
    public JSON saveUserInfo(Admin admin) {
        return adminService.saveAdminInfo(admin);
    }

    /*
    @Param user
    @return
     */
    @GetMapping("/verifyAdminPwd")
    @ResponseBody
    @CrossOrigin
    public JSON verifyUserPwd(Admin admin) {
        return adminService.verifyAdminPwd(admin);
    }



    @GetMapping("/queryAdmin")
    @ResponseBody
    @CrossOrigin
    public JSON queryAdmin(@RequestParam("page") int page, @RequestParam("limit") int limit) {
        JSONObject json = new JSONObject();
        int page1 = page - 1;
        int page2 = page1 * limit;
        json.put("code", 0);
        json.put("msg", "");
        json.put("count", adminService.queryAdmin(0, 100000).size());
        json.put("data", adminService.queryAdmin(page2, limit));
        return json;
    }


}
